package com.xudow.app.newui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.activeshare.edu.ucenter.models.course.StudyTimeItem;
import com.activeshare.edu.ucenter.models.user.InspectionTeam;
import com.xudow.app.Config;
import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.module.PictureActivity;
import com.xudow.app.newui.base.BaseUiActivity;
import com.xudow.app.newui.task.InspectionTeamTask;
import com.xudow.app.ui.task.AgencyTeacherTask;
import com.xudow.app.ui.task.GetClassTimesTask;
import com.xudow.app.util.ImageUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import it.sephiroth.android.library.widget.AdapterView;
import it.sephiroth.android.library.widget.HListView;

/**
 * 机构老师详情
 */
public class ClassTimesTableActivity extends BaseUiActivity {

   @BindView(R.id.lv)
    ListView lv;

   @BindView(R.id.timers_lv)
   ListView timers_lv;

    private String courseId="";
    MyAdapter countadapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_table);
        countadapter=new MyAdapter(this);
        lv.setDivider(null);
        lv.setAdapter(countadapter);

    }

    @Override
    protected void initData() {
        courseId=getIntent().getStringExtra("courseId");
        HashMap<String,String> map=new HashMap<String,String>();
        Log.e("courseid",courseId);
        map.put("courseId",courseId);
        GetClassTimesTask task=new GetClassTimesTask(this,getTeamDataHandler);
        task.execute(map);
    }
    private List<StudyTimeItem> teams;
    private Handler getTeamDataHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==InspectionTeamTask.SUCCESS){
                teams=(List<StudyTimeItem>)msg.obj;
                Log.e("teamsize:",teams.size()+"" );
                if (null!=teams&&teams.size()>0){
                    countadapter.setData(teams);
                }
            }else
                getMyApp().makeToast(msg.getData().getString("errMessage"));
        }
    };
    public void onBackBtnClick(View view) {
        finish();
    }

    @Override
    protected void initListener() {

    }



    class MyAdapter extends BaseAdapter{
        Context cnt;
        List<StudyTimeItem> data;

        public MyAdapter(Context cnt) {
            this.cnt = cnt;
        }

        public void setData(List<StudyTimeItem> data){
            this.data=data;
            notifyDataSetChanged();
        }
        @Override
        public int getCount() {
            if (null==data||data.size()==0)
                return 0;
            else
                return data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View v, ViewGroup parent) {
            ViewHolder holder;
            if (null==v){
                holder=new ViewHolder();
                v=View.inflate(cnt,R.layout.item_classtimer,null);
                holder.tv1=(TextView)v.findViewById(R.id.tv1);
                holder.tv2=(TextView)v.findViewById(R.id.tv2);
                v.setTag(holder);
            }else
                holder=(ViewHolder)v.getTag();
                StudyTimeItem team=data.get(position);

                holder.tv1.setText(team.getTimes()+"");

                holder.tv2.setText(team.getActualHelpTeacher());

            return v;
        }

        class ViewHolder {
            TextView tv1,tv2;
        }
    }
}
